class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums) {
        vector<int> sum(nums.size(),-1);
        if(nums.size() ==0)
        {
            return {};
        }
        if(nums.size() ==1)
        {
            return sum;
        }
        for(int i=0;i<nums.size();i++)
        {
            int j = (i + 1) % nums.size();
            while(1)
            {
                if(j == i)
                {
                    break;
                }
                else if(nums[j]>nums[i])
                {
                    sum[i] = nums[j];
                    break;
                }
                if(j+1 == nums.size())
                {
                    j = 0;
                }
                else
                {
                    j = (j + 1) % nums.size();
                }
            }
        }
        return sum;
    }
};
